/**
 * 计算孕期
 */
module.exports = {
    /**
     * 获取怀孕天数(怀孕天数 = 当前时间 - ( 预产期 - 280天 ))
     */
    getPregnantDayNum: function (now, prePeriod) {
        if (!prePeriod) {
            return -1;
        }
        var currentDate = new Date(now.getFullYear(), now.getMonth(), now.getDate());
        var prePeriodDate = new Date(prePeriod.getFullYear(), prePeriod.getMonth(), prePeriod.getDate());
        var date = new Date(prePeriod.getFullYear(), prePeriod.getMonth(), prePeriod.getDate() - ( 280 - 1 ));
        if (0 <= currentDate - date && 0 <= prePeriodDate - currentDate) {
            currentDate.setDate(currentDate.getDate() + 280);
            return Math.ceil((currentDate - prePeriodDate) / (24 * 60 * 60 * 1000.0));
        } else {
            return -1;
        }
    }
};
